package com.gmrz.uap.config;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Wang Haifeng
 */
public class ResponseWrapper extends HttpServletResponseWrapper {

    private final CharArrayWriter responseWriter;

    public ResponseWrapper(HttpServletResponse response) {
        super(response);
        responseWriter = new CharArrayWriter();
    }

    @Override
    public PrintWriter getWriter() throws IOException {
        return new PrintWriter(responseWriter);
    }

    public String getResponsePayload() {
        return responseWriter.toString();
    }
}